package com.cloudptt.wp.ui.message;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.cloudptt.api.product.Product;
import com.cloudptt.api.product.ProductConst;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.api.product.operator.MsgOperator;
import com.cloudptt.wp.R;
import com.cloudptt.wp.ScreenManager;
import com.cloudptt.wp.SysApplication;
import com.cloudptt.wp.ui.BaseActivity;
import com.cloudptt.wp.ui.message.adapter.MessageStatusAdapter;
import com.mcptt.db.model.SessionInfo;
import com.mcptt.db.model.SessionReadStatus;

import java.util.List;

public class MessagesStatusActivity extends BaseActivity implements View.OnClickListener {

    private MessageStatusAdapter mAdapter;
    private List<SessionReadStatus> readStatusesList = null;
    private ListView memberLv;
    private SessionInfo sessionInfo = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//        window.setStatusBarColor(getResources().getColor(R.color.app_theme_color_primary));
        window.setStatusBarColor(getResources().getColor(R.color.gradient_end));

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_read_status);
        TextView tv = (TextView) findViewById(R.id.titleTv);

        ImageView iv = (ImageView) findViewById(R.id.back_up_icon);
        iv.setOnClickListener(this);

        sessionInfo =(SessionInfo)getIntent().getSerializableExtra(SessionActivity.KEY);
        Log.debug(this.getClass(),"onCreate sessionInfo =  "+ sessionInfo);
        if(sessionInfo.isFdMsg()) {
            tv.setText(R.string.title_message_file_status);
        }
        else
        {
            tv.setText(R.string.title_message_txt_status);
        }
        memberLv = (ListView) findViewById(R.id.memberLv);

        SysApplication app = ((SysApplication) getApplicationContext());
        Product product = app.getProduct();
        MsgOperator op = (MsgOperator)product.getOperator(ProductConst.Func_Msg);
        readStatusesList = op.getSessionReadStatusList(sessionInfo);
        mAdapter = new MessageStatusAdapter(MessagesStatusActivity.this,sessionInfo,readStatusesList);
        memberLv.setAdapter(mAdapter);
        memberLv.requestFocus();
        memberLv.setSelection(0);
        initNotificationLayout();
    }
    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.back_up_icon)
        {
            this.finish();
            overridePendingTransition( R.anim.in_from_left, R.anim.out_to_right );
        }
    }

    private void updateListDataByeType()
    {
        SysApplication app = ((SysApplication) getApplicationContext());
        Product product = app.getProduct();
        MsgOperator op = (MsgOperator)product.getOperator(ProductConst.Func_Msg);
        List<SessionReadStatus> readStatusesList = op.getSessionReadStatusList(sessionInfo);
        Log.debug(this.getClass(), "updateListDataByeType readStatusesList "+ readStatusesList);
        {
            mAdapter.setMemList(readStatusesList);
            mAdapter.notifyDataSetChanged();
            memberLv.requestFocus();
            memberLv.setSelection(0);
        }
    }


}
